#include "RestRoom.hh"
#include <iostream>
#include <limits>
#include "IO.hh"

RestRoom::RestRoom(const std::string& name, const std::string& description) : Room(name, description) {}

void RestRoom::enterRoom(Player& player) {
    std::cout << "\nYou enter the Rest Room. It's quiet and safe here.\n";
    std::cout << "You take a moment to recover your strength...\n";

    // 使用 restoreHealth
    unsigned recovered = std::min(20u, player.getMaxHealth() - player.getHealth());
    player.restoreHealth(recovered);
    std::cout << "Recovered " << recovered << " HP! Current HP: " << player.getHealth() << "\n";

    while (true) {
        IO::showRestRoomMenu();
        int input=IO::getNumber();
        if (input == 1) {
            player.displayStatus();
        }else if (input == 2) {
            std::cout << "Enter secret code: ";
            std::string codeInput=IO::getString();
            if (codeInput == secretCode) {
                std::cout << "\nYou entered the secret code! A hidden passage opens...\n";
                escapeUnlocked = true;
            } else {
                std::cout << "Nothing happens...\n";
            }
        } else if (input == 3) {
            std::cout << "You decide to leave the Rest Room.\n";
            break;
        } else {
            std::cout << "Unrecognized input. Try again.\n";
        }
    }
}

bool RestRoom::hasEscapeUnlocked() const {
    return escapeUnlocked;
}

